package com.rcp.steve.crm.editor;

import java.io.File;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

import de.vogella.jface.treeviewer.model.Todo;

public class EditorParent extends EditorPart {
	private OleClientSite site;
	private OleFrame oleFrame;
	protected Todo todo;
	public EditorParent() {
		// TODO Auto-generated constructor stub
	}

	public void createPartControl(Composite parent) {
//		setPartName(getPartName()+":"+todo.getName());
		try {
			oleFrame = new OleFrame(parent, SWT.TOP);  
            {  
                try {  
                	File file = new File(todo.getUrl());
                	site = new org.eclipse.swt.ole.win32.OleClientSite(oleFrame,  
                            org.eclipse.swt.SWT.NONE, file);  
                    site.setBounds(0, 0, 104, 54);  
                    site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
                } catch (org.eclipse.swt.SWTException e) {  
                	e.printStackTrace();
                    return;  
                }  
            }  
        
		} catch (SWTError e) {
			System.out.println("Unable to open activeX control");
			return;
		}
	}

	public void setFocus() {
		// TODO Auto-generated method stub

	}

	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		
	}

	public void doSaveAs() {
		// TODO Auto-generated method stub
		
	}

	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		if (!(input instanceof Todo)) {
			throw new RuntimeException("Wrong input");
		}
		todo = (Todo)input;
		setSite(site);
		setInput(input);
	}

	public boolean isDirty() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}
}
